package com.zfx.service.impl;

import com.github.pagehelper.PageHelper;
import com.zfx.mapper.ITemplateMapper;
import com.zfx.pojo.Template;
import com.zfx.service.ITemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @description: 运营账号服务层接口实现类
 * @author: zfx
 */
@Service
public class TemplateServiceImpl implements ITemplateService {

    @Autowired
    private ITemplateMapper templateMapper;

    @Transactional(readOnly = true)
    @Override
    public List<Template> findByIdAndName(Template template, int page, int size) {
        PageHelper.startPage(page, size);
        return templateMapper.findByIdAndName(template);
    }

    @Transactional(readOnly = true)
    @Override
    public Template findById(Integer id) {
        return templateMapper.selectByPrimaryKey(id);
    }

    @Transactional(readOnly = true)
    @Override
    public List<Template> findByTemplate(Template template, int page, int size) {
        PageHelper.startPage(page, size);
        return templateMapper.select(template);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int save(Template template) {
        return templateMapper.insert(template);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int deleteById(Integer id) {
        return templateMapper.deleteByPrimaryKey(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int update(Template template) {
        return templateMapper.updateByPrimaryKeySelective(template);
    }

    @Transactional(readOnly = true)
    @Override
    public int countByIdAndName(Template template) {
        return templateMapper.selectCount(template);
    }

    @Override
    public int countByTemplate(Template template) {
        return templateMapper.selectCount(template);
    }
}
